//
//  KnowledgeOneImageCell.m
//  Water
//
//  Created by yh on 2017/12/19.
//  Copyright © 2017年 chenguibang. All rights reserved.
//

#import "KnowledgeOneImageCell.h"
#import <Masonry/Masonry.h>
#import <YYKit/UIColor+YYAdd.h>
#import <SDWebImage/UIImageView+WebCache.h>

@implementation KnowledgeOneImageCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    self.knowledgeTitle = [[UILabel alloc]init];
    [self.contentView addSubview:self.knowledgeTitle];
    self.knowledgeTitle.font = [UIFont systemFontOfSize:19];
    self.knowledgeTitle.preferredMaxLayoutWidth = self.contentView.frame.size.width;
    [self.knowledgeTitle setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    [self.knowledgeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(15);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
    }];
    

    
    
    self.knowledgeImage = [[UIImageView alloc]init];
    self.knowledgeImage.contentMode = UIViewContentModeScaleAspectFill;
    self.knowledgeImage.clipsToBounds = YES;
    [self.contentView addSubview:self.knowledgeImage];
    [self.knowledgeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.knowledgeTitle.mas_bottom).offset(15);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.height.equalTo(@120);
    }];
    
    
    
    self.knowledgeDetail = [[UILabel alloc]init];
    [self.contentView addSubview:self.knowledgeDetail];
    self.knowledgeDetail.textColor = UIColorHex(0x999999);
    self.knowledgeDetail.font = [UIFont systemFontOfSize:14];
    self.knowledgeDetail.numberOfLines = 3;
    self.knowledgeDetail.preferredMaxLayoutWidth = self.contentView.frame.size.width;
    [self.knowledgeDetail setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    [self.knowledgeDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.knowledgeImage.mas_bottom).offset(15);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-15);
    }];
    
    
}

- (void)setDataModel:(id)data{
    self.knowledgeTitle.text = data[@"title"];
    self.knowledgeDetail.text = data[@"content"];;
    
    [self.knowledgeImage sd_setImageWithURL:[NSURL URLWithString:data[@"images"][0]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
      
//        [self.knowledgeImage mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.height.equalTo(@200);
//        }];
//
//        if (cacheType != SDImageCacheTypeMemory) {
//            id<KnowledgeCellHandleDelegate> delegate = self.delegate;
//            if (delegate) {
//                [delegate reload];
//            }
//        }
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
